package com.aizuda.oss.autoconfigure;

import com.aizuda.oss.OssEndpoint;
import com.aizuda.oss.OssTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Classname OssAutoConfiguration
 * @Date 2022/4/7 16:24
 * @Created by 87766867@qq.com
 */
@Configuration
@EnableConfigurationProperties({ OssProperties.class })
public class OssAutoConfiguration {

    @Autowired
    private  OssProperties properties;

    @Bean
    @ConditionalOnMissingBean(OssTemplate.class)
    @ConditionalOnProperty(name = "aizuda.oss.enable", havingValue = "true", matchIfMissing = true)
    public OssTemplate ossTemplate() {
        return new OssTemplate(properties);
    }

    @Bean
    @ConditionalOnMissingBean(OssEndpoint.class)
    @ConditionalOnProperty(name = "aizuda.oss.info", havingValue = "true")
    public OssEndpoint ossEndpoint(OssTemplate ossTemplate) {
        return new OssEndpoint(ossTemplate);
    }
}
